package org.lexicon.ontologydocumentor;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;

class OntologyDocumentTransformerTest {

	OntologyDocumentTransformer odt;
	OntologyDocument od;
	String ontology = '''
	
	
	<rdf:RDF
	    xmlns:rss="http://purl.org/rss/1.0/"
	    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
	    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
	    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
	    xmlns:owl="http://www.w3.org/2002/07/owl#"
	    xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
	    xmlns:daml="http://www.daml.org/2001/03/daml+oil#"
	    xmlns:dc="http://purl.org/dc/elements/1.1/"
	    xmlns:dcterms="http://purl.org/dc/terms/"
	    xmlns="http://www.purl.org/net/ontology/beer#"
	>
	
	  <owl:Ontology rdf:about="">
	  	<dc:contributor xml:lang="en">Test contributors</dc:contributor>
	  	<dc:modified >11 jan 1977</dc:modified>
		<dc:creator xml:lang="en">Test Person</dc:creator>
		<dc:rights xml:lang="en">The Beer ontology is available under the Creative Commons Attribution 3.0 Unported license; see http://creativecommons.org/licenses/by/3.0/. In a nutshell, you are free to copy, distribute and transmit the work; to remix/adapt the work (e.g. to import the ontology and create specializations of its elements), as long as you attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Proper Attribution: Simply include the statement &quot;This work is based on the GoodRelations ontology, developed by Martin Hepp&quot; and link back to http://purl.org/goodrelations/</dc:rights>
		<dc:subject xml:lang="en">Beer</dc:subject>
		<dc:title xml:lang="en">The Beer Ontology</dc:title>
		<dcterms:license rdf:resource="http://creativecommons.org/licenses/by/3.0/"/>
		<rdfs:seeAlso rdf:resource="http://purl.org/goodrelations/"/>
	  
	    <owl:versionInfo>beer_v0.4.owl, based on http://purl.org/net/ontology/beer_v0.3.owl</owl:versionInfo>
	    <rdfs:label>Beer Ontology, OWL Lite</rdfs:label>
	    <rdfs:comment>
	    	An ontology that models types of beer and brewers/brands.
		http://purl.org/net/ontology/beer.owl
		http://purl.org/net/dayf/wiki/Ontology_Beer
		
		WordNet		beer -- (a general name for alcoholic beverages made by fermenting a cereal (or mixture of cereals) flavored with hops)
				http://www.cogsci.princeton.edu/cgi-bin/webwn2.0?stage=1&amp;word=beer
		
		History		Based on http://www.csd.abdn.ac.uk/research/AgentCities/ontologies/beer#
		
	    	2004-04-02	* Converted to OWL-Lite by David Aumueller (dayf.de) and http://www.mindswap.org/2002/owl.html
				* Changed concept hierarchy of beers: added top/bottom-fermention.
		2004-08-24	* Removed FuzzyMeasure.
				* Added some German labels, a Property, some Instances.
	
		@todo		* revamp completely, use http://de.wikipedia.org/wiki/Bier
				* model constraints
				* How about some instances? See http://brewery.org/brewery/library/AlClbinger.html  !!
				* Percentage as subclass of float?
				
		Hints		* model purity requirements (german purity law): barley/wheat (kindof grain): malt, hops, water (and yeast (yet unknown around 1516))
				* For the preparation of beer, only malt, hops, yeast and water can be used.
				* Typically, beers are made from water, malted barley, hops, fermented by yeast. The addition of other flavorings or sources of sugar is not uncommon.
	    </rdfs:comment>
	  </owl:Ontology>
	  <owl:Class rdf:ID="Saaz">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Hops"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Beer"/>
	  <owl:Class rdf:ID="Cascade">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Hops"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="IndiaPaleAle">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Ale"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Barley">
	    <rdfs:label xml:lang="de">Gerste</rdfs:label>
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Grain"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Microbrewery">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Brewery"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Ingredient"/>
	  <owl:Class rdf:ID="ImperialStout">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Stout"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Ale">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#TopFermentedBeer"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Pilsner">
	    <rdfs:label xml:lang="de">Pils</rdfs:label>
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#BottomFermentedBeer"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Region"/>
	  <owl:Class rdf:ID="Hops"/>
	  <owl:Class rdf:ID="Galena">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Hops"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="White">
	    <rdfs:label xml:lang="de">Weizenbier</rdfs:label>
	    <rdfs:label xml:lang="en">Wheat Beer</rdfs:label>
	    <rdfs:comment xml:lang="de">Weissbier</rdfs:comment>
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#TopFermentedBeer"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Yeast">
	    <rdfs:label xml:lang="de">Hefe</rdfs:label>
	    <rdfs:subClassOf rdf:resource="#Ingredient"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Brewery">
	    <rdfs:subClassOf>
	      <owl:Class rdf:ID="Organization"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Willamette">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Hops"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Bitter">
	    <rdfs:subClassOf rdf:resource="#Ale"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Chocolate">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Malt"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Malt">
	    <rdfs:label xml:lang="de">Malz</rdfs:label>
	    <rdfs:subClassOf rdf:resource="#Ingredient"/>
	  </owl:Class>
	  <owl:Class rdf:ID="TopFermentedBeer">
	    <rdfs:label xml:lang="de">Obergaeriges Bier</rdfs:label>
	    <rdfs:subClassOf rdf:resource="#Beer"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Lager">
	    <rdfs:label xml:lang="de">Helles</rdfs:label>
	    <rdfs:subClassOf rdf:resource="#BottomFermentedBeer"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Munich">
	    <rdfs:subClassOf rdf:resource="#Malt"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Town">
	    <rdfs:subClassOf rdf:resource="#Region"/>
	  </owl:Class>
	  <owl:Class rdf:ID="BottomFermentedBeer">
	    <rdfs:label xml:lang="de">Untergaeriges Bier</rdfs:label>
	    <rdfs:subClassOf rdf:resource="#Beer"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Tettnang">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Hops"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Mild">
	    <rdfs:subClassOf rdf:resource="#Ale"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Perle">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Hops"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Bock">
	    <rdfs:subClassOf rdf:resource="#BottomFermentedBeer"/>
	  </owl:Class>
	  <owl:Class rdf:ID="ScotchAle">
	    <rdfs:subClassOf rdf:resource="#Ale"/>
	  </owl:Class>
	  <!--<owl:Class rdf:ID="Name"/>-->
	  <owl:Class rdf:ID="Black">
	    <rdfs:subClassOf rdf:resource="#Malt"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Hops">
	    <rdfs:label xml:lang="en">Hops</rdfs:label>
	    <rdfs:subClassOf rdf:resource="#Ingredient"/>
	    <rdfs:label xml:lang="en">Vine</rdfs:label>
	    <rdfs:label xml:lang="de">Hopfen</rdfs:label>
	  </owl:Class>
	  <owl:Class rdf:ID="Wheat">
	    <rdfs:subClassOf rdf:resource="#Grain"/>
	    <rdfs:label xml:lang="de">Weizen</rdfs:label>
	  </owl:Class>
	  <owl:Class rdf:ID="BrownAle">
	    <rdfs:subClassOf rdf:resource="#Ale"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Grain">
	    <rdfs:subClassOf rdf:resource="#Ingredient"/>
	    <rdfs:label xml:lang="de">Getreide</rdfs:label>
	  </owl:Class>
	  <owl:Class rdf:ID="Carapils">
	    <rdfs:subClassOf rdf:resource="#Malt"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Porter">
	    <rdfs:subClassOf rdf:resource="#TopFermentedBeer"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Water">
	    <rdfs:subClassOf rdf:resource="#Ingredient"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Chinook">
	    <rdfs:subClassOf rdf:resource="#Hops"/>
	  </owl:Class>
	  <owl:Class rdf:ID="PaleAle">
	    <rdfs:subClassOf rdf:resource="#Ale"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Pale">
	    <rdfs:subClassOf rdf:resource="#Malt"/>
	  </owl:Class>
	  <owl:Class rdf:ID="DryStout">
	    <rdfs:subClassOf>
	      <owl:Class rdf:about="#Stout"/>
	    </rdfs:subClassOf>
	  </owl:Class>
	  <owl:Class rdf:ID="Hallertau">
	    <rdfs:subClassOf rdf:resource="#Hops"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Association">
	    <rdfs:subClassOf rdf:resource="#Organization"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Stout">
	    <rdfs:subClassOf rdf:resource="#Porter"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Festival"/>
	  <owl:Class rdf:ID="KentGoldings">
	    <rdfs:subClassOf rdf:resource="#Hops"/>
	  </owl:Class>
	  <owl:Class rdf:ID="MountHood">
	    <rdfs:subClassOf rdf:resource="#Hops"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Award"/>
	  <owl:Class rdf:ID="SweetStout">
	    <rdfs:subClassOf rdf:resource="#Stout"/>
	  </owl:Class>
	  <owl:Class rdf:ID="Caramel">
	    <rdfs:subClassOf rdf:resource="#Malt"/>
	  </owl:Class>
	  <owl:ObjectProperty rdf:ID="maltedTo">
	    <rdfs:domain rdf:resource="#Grain"/>
	    <rdfs:range rdf:resource="#Malt"/>
	    </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="madeFrom">
	    <rdfs:range rdf:resource="#Ingredient"/>
	    <rdfs:domain rdf:resource="#Beer"/>
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="locatedIn">
	    <rdfs:range rdf:resource="#Region"/>
	    <rdfs:domain rdf:resource="#Brewery"/>
	    <!-- <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/> -->
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="awardCategory">
	    <rdfs:domain rdf:resource="#Award"/>
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="awardedAt">
	    <rdfs:range rdf:resource="#Festival"/>
	    <rdfs:domain rdf:resource="#Award"/>
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="awarded">
	    <rdfs:range rdf:resource="#Award"/>
	    <rdfs:domain rdf:resource="#Beer"/>
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="sponsors">
	    <rdfs:domain rdf:resource="#Association"/>
	    <rdfs:range rdf:resource="#Festival"/>
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="brews">
	    <rdfs:range rdf:resource="#Beer"/>
	    <rdfs:domain rdf:resource="#Brewery"/>
	  </owl:ObjectProperty>
	  <owl:ObjectProperty rdf:ID="brewedBy">
	    <owl:inverseOf rdf:resource="#brews"/>
	    <rdfs:domain rdf:resource="#Beer"/>
	    <rdfs:range rdf:resource="#Brewery"/>
	  </owl:ObjectProperty>
	  <!--
	  <owl:DatatypeProperty rdf:ID="hasProperty" />
	  -->
	  <owl:DatatypeProperty rdf:ID="hasContent" >
	    <!--<rdfs:subPropertyOf rdf:resource="#hasProperty"/>-->
	    <rdfs:domain rdf:resource="#Beer"/>
	    <rdfs:comment>only for test purposes</rdfs:comment>
	  </owl:DatatypeProperty>
	  <owl:DatatypeProperty rdf:ID="hasAlcoholicContent">
	    <rdfs:subPropertyOf rdf:resource="#hasContent"/>
	    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
	    <rdfs:domain rdf:resource="#Beer"/>
	    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
	  </owl:DatatypeProperty>
	  <owl:DatatypeProperty rdf:ID="hasOriginalWortContent">
	    <rdfs:subPropertyOf rdf:resource="#hasContent"/>
	    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
	    <rdfs:domain rdf:resource="#Beer"/>
	    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
	  </owl:DatatypeProperty>
	  <!--
	  <owl:Class rdf:ID="OriginalWort">
	    <rdfs:label xml:lang="en">Original wort</rdfs:label>
	    <rdfs:label xml:lang="de">Stammwuerze</rdfs:label>
	  </owl:Class>
	  -->
	  <Bock rdf:ID="Grafentrunk"/>
	  <Pilsner rdf:ID="Jever"/>
	  <Lager rdf:ID="Krieger">
	    <rdfs:label xml:lang="de">Krieger Hell</rdfs:label>
	    <hasAlcoholicContent>4.5</hasAlcoholicContent>
	    <brewedBy>
	      <Brewery rdf:ID="KriegerBrauerei">
	        <locatedIn>
	          <Town rdf:ID="LandauIsar">
	            <rdfs:comment>Landau an der Isar, Germany</rdfs:comment>
	          </Town>
	        </locatedIn>
	      </Brewery>
	    </brewedBy>
	  </Lager>
	  <White rdf:ID="Paulaner"/>
	  <Ale rdf:ID="Boddingtons"/>
	  <Ale rdf:ID="Tetleys"/>
	  <White rdf:ID="Hoegaarden"/>
	</rdf:RDF>

	
	''' 
	
	@Test
	public void testTitleTransformation(){
		assert this.od.getTitle() =~ "The Beer Ontology";
	}
	
	@Test
	public void testDescriptionTransformation(){
		assert this.od.getDescription() =~ "An ontology that models types of beer and brewers/brands.";
	}
	
	@Test
	public void testAuthorsTransformation(){
		assert this.od.getAuthors().find{it =~ "Test Person"};
	}
	
	@Test
	public void testVersionTransformation(){
		assert this.od.getThisVersion() =~ "v0.4";
	}
	
	@Test
	public void testLastUpdateTransformation(){
		assert this.od.getLastUpdated() =~ "11 jan 1977";
	}
	
	@Test
	public void testLicenseTransformation(){
		assert this.od.getLicense() =~ "http://creativecommons.org/licenses/by/3.0/";
	}
	
	@Test
	public void testRightsTransformation(){
		assert this.od.getRights() =~ "The Beer ontology is available under the Creative Commons Attribution 3.0";
	}
	
	@Test
	public void testContributorsTransformation(){
		assert this.od.getContributors().find{it =~ "Test contributors"};
	}
	
	@Before
	public void setUp() throws Exception {
		ByteArrayInputStream bais = new ByteArrayInputStream(this.ontology.getBytes()); 
		OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
		om.read(bais, "http://www.purl.org/net/ontology/beer#");
		this.odt = new OntologyDocumentTransformer(om);
		this.od = this.odt.transform();
	}

	@After
	public void tearDown() throws Exception {
		this.odt = null;
		this.od = null;
	}
}
